package com.example.controller;

import com.example.entity.Order;
import com.example.response.Result;
import com.example.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 创建新订单
     */
    @PostMapping
    public Result insert(@PathVariable List<Order> orders){
        log.info("批量下单操作, 商品ids:{}",orders);
        orderService.insert(orders, LocalDateTime.now());
        return Result.success();
    }

    /**
     * 查看某个用户的所有订单数据
     */
    @GetMapping("/{id}")
    public Result select(Integer id){
        log.info("查看某个用户的所有订单");
        List<Order> orderList = orderService.select(id);
        return Result.success(orderList);
    }
}
